package com.ktgj.customer.common;

import com.alibaba.fastjson.JSONObject;
import com.ktgj.common.core.utils.xml.XElement;
import com.ktgj.customer.domain.Insurance.Auis;
import com.ktgj.customer.domain.Insurance.AuisVo;
import com.ktgj.customer.domain.Insurance.PolicyInfo;

public class hhh {
    public static void main(String[] args) {
        String rst = "<Auis><ProcessedSystemIndex>1</ProcessedSystemIndex><RequestType>auis.api.asi.insure</RequestType><RequestId>d4aee8a5423742e8bf0546e4469e10fc</RequestId><ResponseTime>2022-07-13 18:15:13</ResponseTime><CompanyId>jsj</CompanyId><ResultCode>000000</ResultCode><ResultMsg>API-执行正常</ResultMsg><ResponseData><![CDATA[{\"ReturnCode\":\"0\",\"ReturnMessage\":\"Surrender create success！\",\"SerialNumber\":\"d97e229a656e40999f2dac1a38c72b13\",\"policyInfo\":{\"PolicyNo\":\"T220713000005030170710\",\"Code\":\"0\",\"Message\":\"Surrender create success！\",\"EPolicyUrl\":\"\"}}]]></ResponseData></Auis>";

        int countForward = rst.indexOf("<ResponseData>");
        int countBack = rst.indexOf("</ResponseData>");
        String xml = rst.substring(0, countForward + 14);
        xml = xml + rst.substring(countBack);

        String json = rst.substring(countForward + 14, countBack);
        json = json.substring(9);
        json = json.substring(0, json.length() - 3);
        XElement root = XElement.loadXml(xml);

        AuisVo auisVo = null;
        if (json != null && !json.equals("null")){
            String[] split = json.split("\\{");

            String tmpPolicyInfo = "{" + split[split.length - 1].substring(0, split[split.length - 1].length() - 2) + "}";

            String tmpAuisVo = "{" + split[split.length - 2] + "\"\"}";

            auisVo = JSONObject.parseObject(tmpAuisVo, AuisVo.class);
            PolicyInfo policyInfo = JSONObject.parseObject(tmpPolicyInfo, PolicyInfo.class);
            policyInfo.setEPolicyUrl(policyInfo.getEPolicyUrl().substring(9, policyInfo.getEPolicyUrl().length() - 3));
            auisVo.setPolicyInfo(policyInfo);

            Auis auis = new Auis();
            auis.setResponseData(auisVo);
            System.out.println(auis);
        }
    }
}
